/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package course.ya.doc.from.code;

import course.ya.doc.from.code.model.ast.StatementTree;
import course.ya.doc.from.code.model.ast.StatementTreeBuilder;
import course.ya.doc.from.code.model.drawing.Draftsman;
import course.ya.doc.from.code.model.lexer.project.Keys;
import course.ya.doc.from.code.model.lexer.project.NodeTree;
import course.ya.doc.from.code.model.lexer.project.SyntaxTree;
import course.ya.doc.from.code.model.lexer.project.WrapperScanner;
import course.ya.doc.from.code.model.statements.IStatementFactory;
import course.ya.doc.from.code.model.statements.StateFactory;
import course.ya.doc.from.code.model.statements.StatementFactory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;

/**
 *
 * @author Admin
 */
public class Front {

    private WrapperScanner ws;
    private StatementTreeBuilder stb;
    private Draftsman df;

    public Front(String name) throws IOException {
        if (name != null) {
            ws = new WrapperScanner(name);
        }
    }
    public void run() throws IOException {
        Map<Keys, SyntaxTree> mapSyntax = ws.scan();
        ArrayList listTree = new ArrayList(mapSyntax.values());
        ArrayList listKey = new ArrayList(mapSyntax.keySet());
        IStatementFactory factory;
        factory = StateFactory.getInstance();
        ListIterator<SyntaxTree> iter = listTree.listIterator();
        ListIterator<Keys> keyIter=listKey.listIterator();

        while (iter.hasNext()) {
            SyntaxTree st = iter.next();
            NodeTree node = st.getRoot();
            stb = new StatementTreeBuilder(node, factory, 
                                           keyIter.next().getFullName());
            StatementTree tr = stb.build();
            df = new Draftsman(tr, tr.getName());
           // df.draw();
        }
    }
}
